/*
 * SubGrupoRegimenEliminar.java
 *
 * Created on 30 de abril de 2008, 12:40 PM
 */
package org.contabilidad.regimen;

import org.mybeans.Sesion;
import org.mybeans.SubGrupoRegimenBeans;
import org.mybeans.GrupoRegimenBeans;
 
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author  avbravo
 */
public class SubGrupoRegimenActualizarFrame extends javax.swing.JFrame {

    SubGrupoRegimenBeans subGrupoRegimenBeans;
    Sesion sesion;
    GrupoRegimenBeans grupoRegimenBeans;
boolean focoGrupo = false;
boolean focoSubGrupo = false;
    /** Creates new form SubGrupoRegimenEliminar */
    public SubGrupoRegimenActualizarFrame() {
        initComponents();
           /*
             * Fondo
             */

            
              
             

             
             

            /*
             * fin del fondo
             */
        sesion = new Sesion();
        subGrupoRegimenBeans = new SubGrupoRegimenBeans();
        grupoRegimenBeans = new GrupoRegimenBeans();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldIdSubGrupoRegimen = new javax.swing.JTextField();
        jTextFieldSubGrupoRegimen = new javax.swing.JTextField();
        jButtonConsultarSubGrupoRegimen = new javax.swing.JButton();
        jButtonBuscarSubGrupo = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonActualizar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldIdGrupoRegimen = new javax.swing.JTextField();
        jButtonConsultarContribuyentes = new javax.swing.JButton();
        jButtonBuscarContribuyentes = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldGrupo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacion = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Actualizar SubGrupo de Regimen");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setText("Cod. SubGrupo");

        jLabel4.setText("Sub Grupo");

        jTextFieldIdSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdSubGrupoRegimenActionPerformed(evt);
            }
        });

        jButtonConsultarSubGrupoRegimen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/consultar.png"))); // NOI18N
        jButtonConsultarSubGrupoRegimen.setToolTipText("Consultar");
        jButtonConsultarSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarSubGrupoRegimenActionPerformed(evt);
            }
        });

        jButtonBuscarSubGrupo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarSubGrupo.setToolTipText("Buscar");
        jButtonBuscarSubGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarSubGrupoActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonActualizar.setToolTipText("Actualizar");
        jButtonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarActionPerformed(evt);
            }
        });

        jLabel5.setText("Codigo Grupo");

        jTextFieldIdGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdGrupoRegimenActionPerformed(evt);
            }
        });

        jButtonConsultarContribuyentes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/consultar.png"))); // NOI18N
        jButtonConsultarContribuyentes.setToolTipText("Consultar Contribuyente");
        jButtonConsultarContribuyentes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarContribuyentesActionPerformed(evt);
            }
        });

        jButtonBuscarContribuyentes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarContribuyentes.setToolTipText("Buscar");
        jButtonBuscarContribuyentes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarContribuyentesActionPerformed(evt);
            }
        });

        jLabel6.setText("Grupo");

        jTextFieldGrupo.setEditable(false);

        jLabel7.setText("Observacion");

        jTextAreaObservacion.setColumns(20);
        jTextAreaObservacion.setRows(5);
        jScrollPane1.setViewportView(jTextAreaObservacion);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jTextFieldGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldIdGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonConsultarContribuyentes, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonBuscarContribuyentes)
                                .addContainerGap())
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(11, 11, 11)
                                    .addComponent(jButtonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap())
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jTextFieldIdSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jButtonConsultarSubGrupoRegimen)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jButtonBuscarSubGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jTextFieldSubGrupoRegimen, javax.swing.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE))
                                    .addGap(24, 24, 24)))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldIdSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonConsultarSubGrupoRegimen)
                    .addComponent(jButtonBuscarSubGrupo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jTextFieldIdGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonConsultarContribuyentes)
                    .addComponent(jButtonBuscarContribuyentes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonConsultarSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarSubGrupoRegimenActionPerformed
 
    ConsultarSubGrupo();
}//GEN-LAST:event_jButtonConsultarSubGrupoRegimenActionPerformed

private void jButtonBuscarSubGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarSubGrupoActionPerformed
 
    SubGrupoRegimenBusquedaFrame subGrupoRegimenBusquedaFrame = new SubGrupoRegimenBusquedaFrame();
    subGrupoRegimenBusquedaFrame.setLocationRelativeTo(null);
    subGrupoRegimenBusquedaFrame.setVisible(true);
  focoGrupo = false;
     focoSubGrupo = true;
}//GEN-LAST:event_jButtonBuscarSubGrupoActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed
 
    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarActionPerformed
 
    try {
        String idSubGrupoRegimen = this.jTextFieldIdSubGrupoRegimen.getText();
        if (idSubGrupoRegimen == null || idSubGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdSubGrupoRegimen.requestFocus();
            return;
        }


        String SubGrupoRegimen = this.jTextFieldSubGrupoRegimen.getText();
        if (SubGrupoRegimen == null || SubGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el nombre de subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldSubGrupoRegimen.requestFocus();
            return;
        }
        String idGrupoRegimen = this.jTextFieldIdGrupoRegimen.getText();
        if (idGrupoRegimen == null || idGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de grupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdGrupoRegimen.requestFocus();
            return;
        }
        String GrupoRegimen = this.jTextFieldGrupo.getText();
        if (GrupoRegimen == null || GrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo del grupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdGrupoRegimen.requestFocus();
            return;
        }
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String sqlquery = "select * from subgruporegimen where idmunicipio = ? and idsubgruporegimen =?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, idSubGrupoRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();

        if (x == 0) {
            JOptionPane.showMessageDialog(this, "No existe un subgrupo  con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

            return;
        }

        String Observacion = jTextAreaObservacion.getText();
        String sql = "update  subgruporegimen  set subgrupo =?, idgruporegimen = ?,observacion =? where idmunicipio = ? and idsubgruporegimen = ? and activo ='si'";
        PreparedStatement prest = sesion.con.prepareStatement(sql);
prest.setString(1, SubGrupoRegimen);
        prest.setString(2, idGrupoRegimen);
        prest.setString(3, Observacion);        
        prest.setString(4, sesion.getIdmunicipio());
        prest.setString(5, idSubGrupoRegimen);
        int count = prest.executeUpdate();
        sesion.con.close();
        JOptionPane.showMessageDialog(this, "SubGrupo Actualizado exitosamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        subGrupoRegimenBeans.setIdGrupoRegimen(idGrupoRegimen);
        subGrupoRegimenBeans.setObservacion(Observacion);
        subGrupoRegimenBeans.setIdGrupoRegimen(idGrupoRegimen);
        subGrupoRegimenBeans.setSubGrupo(SubGrupoRegimen);
        grupoRegimenBeans.setIdGrupoRegimen(idGrupoRegimen);
        grupoRegimenBeans.setGrupo(GrupoRegimen);
    } catch (Exception ex) {
        System.out.println("Error" + ex);
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonActualizarActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed
 
    Limpiar();
}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jButtonConsultarContribuyentesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarContribuyentesActionPerformed
 
   ConsultarGrupo();
}//GEN-LAST:event_jButtonConsultarContribuyentesActionPerformed

private void jButtonBuscarContribuyentesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarContribuyentesActionPerformed
 
    GrupoRegimenBusquedaFrame grupoRegimenBusquedaFrame = new GrupoRegimenBusquedaFrame();
    grupoRegimenBusquedaFrame.setLocationRelativeTo(null);
    grupoRegimenBusquedaFrame.setVisible(true);
    focoGrupo = true;
     focoSubGrupo = false;
}//GEN-LAST:event_jButtonBuscarContribuyentesActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
      if (focoGrupo) {
                CargarGrupos();
            }
        if (focoSubGrupo) {
                CargarSubGrupos();
            }
     focoGrupo = false;
     focoSubGrupo = false;
}//GEN-LAST:event_formWindowGainedFocus

private void jTextFieldIdSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdSubGrupoRegimenActionPerformed
    // TODO add your handling code here:
     ConsultarSubGrupo();

}//GEN-LAST:event_jTextFieldIdSubGrupoRegimenActionPerformed

private void jTextFieldIdGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdGrupoRegimenActionPerformed
    // TODO add your handling code here:
    ConsultarGrupo();
}//GEN-LAST:event_jTextFieldIdGrupoRegimenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SubGrupoRegimenActualizarFrame().setVisible(true);
            }
        });
    }


    private void ConsultarSubGrupo(){
        try {
        String idSubGrupoRegimen = this.jTextFieldIdSubGrupoRegimen.getText();
        if (idSubGrupoRegimen == null || idSubGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo del subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        String sqlquery = "select * from subgruporegimen where idmunicipio = ? and idsubgruporegimen = ?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, idSubGrupoRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();
        if (x == 0) {
            JOptionPane.showMessageDialog(this, "No existen registros de subgrupo con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String activo = rs.getString("activo");
        if (activo.equals("no")) {
            JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String subgrupo = rs.getString("subgrupo");


        if (subgrupo == null || subgrupo.equals("")) {
            JOptionPane.showMessageDialog(this, "El grupo esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
            return;
        }
        String Observacion = rs.getString("observacion");
        String idGrupoRegimen = rs.getString("idgruporegimen");
        subGrupoRegimenBeans.setIdSubGrupoRegimen(idSubGrupoRegimen);
        subGrupoRegimenBeans.setSubGrupo(subgrupo);
        subGrupoRegimenBeans.setObservacion(Observacion);

        this.jTextFieldIdSubGrupoRegimen.setText(idSubGrupoRegimen);
        this.jTextFieldSubGrupoRegimen.setText(subgrupo);
        jTextFieldIdGrupoRegimen.setText(idGrupoRegimen);
        GrupoRegimenCargar();
        repaint();

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
    }

    private void ConsultarGrupo(){
         try {
        String idGrupoRegimen = this.jTextFieldIdGrupoRegimen.getText();
        if (idGrupoRegimen == null || idGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de grupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        String sqlquery = "select * from gruporegimen where idmunicipio = ? and idgruporegimen = ?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, idGrupoRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();
        if (x == 0) {
            JOptionPane.showMessageDialog(this, "No existen registros de grupo con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String activo = rs.getString("activo");
        if (activo.equals("no")) {
            JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String grupo = rs.getString("grupo");

        if (grupo == null || grupo.equals("")) {
            JOptionPane.showMessageDialog(this, "El grupo esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
            return;
        }
        grupoRegimenBeans.setIdGrupoRegimen(idGrupoRegimen);
        grupoRegimenBeans.setGrupo(grupo);
        this.jTextFieldIdGrupoRegimen.setText(idGrupoRegimen);
        this.jTextFieldGrupo.setText(grupo);
        repaint();

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
    }
    private void Limpiar() {
        jTextFieldIdSubGrupoRegimen.setText("");
        jTextFieldSubGrupoRegimen.setText("");
        jTextFieldGrupo.setText("");
        jTextFieldIdGrupoRegimen.setText("");
        jTextAreaObservacion.setText("");
    }

    public void CargarSubGrupos() {
        try {

            this.jTextFieldIdSubGrupoRegimen.setText(subGrupoRegimenBeans.getIdSubGrupoRegimen());
            this.jTextFieldSubGrupoRegimen.setText(subGrupoRegimenBeans.getSubGrupo());
            jTextAreaObservacion.setText(subGrupoRegimenBeans.getObservacion());
            jTextFieldIdGrupoRegimen.setText(grupoRegimenBeans.getIdGrupoRegimen());
            jTextFieldGrupo.setText(grupoRegimenBeans.getGrupo());

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    public void CargarGrupos() {
        try {

            this.jTextFieldIdGrupoRegimen.setText(grupoRegimenBeans.getIdGrupoRegimen());
            this.jTextFieldGrupo.setText(grupoRegimenBeans.getGrupo());

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    
     private void GrupoRegimenCargar() {
        try {
            String idGrupoRegimen = this.jTextFieldIdGrupoRegimen.getText();
            if (idGrupoRegimen == null || idGrupoRegimen.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el codigo de grupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String sqlquery = "select * from gruporegimen where idmunicipio = ? and idgruporegimen = ?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, sesion.getIdmunicipio());
            psquery.setString(2, idGrupoRegimen);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
                JOptionPane.showMessageDialog(this, "No existen registros de grupo con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String activo = rs.getString("activo");
            if (activo.equals("no")) {
                JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String grupo = rs.getString("grupo");

            if (grupo == null || grupo.equals("")) {
                JOptionPane.showMessageDialog(this, "El grupo esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }
            grupoRegimenBeans.setGrupo(grupo);
            grupoRegimenBeans.setIdGrupoRegimen(idGrupoRegimen);
            CargarSubGrupos();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonActualizar;
    private javax.swing.JButton jButtonBuscarContribuyentes;
    private javax.swing.JButton jButtonBuscarSubGrupo;
    private javax.swing.JButton jButtonConsultarContribuyentes;
    private javax.swing.JButton jButtonConsultarSubGrupoRegimen;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaObservacion;
    private javax.swing.JTextField jTextFieldGrupo;
    private javax.swing.JTextField jTextFieldIdGrupoRegimen;
    private javax.swing.JTextField jTextFieldIdSubGrupoRegimen;
    private javax.swing.JTextField jTextFieldSubGrupoRegimen;
    // End of variables declaration//GEN-END:variables
}
